package com.ny.mingli_measurement.controller;


import ch.qos.logback.classic.Logger;
import com.ny.mingli_measurement.model.TestTable;
import com.ny.mingli_measurement.service.TestTableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ny
 * @since 2021-05-03
 */
@Controller
@RequestMapping("/test-table")
@Slf4j
public class TestTableController {

    @Autowired
    TestTableService service;

    @GetMapping("/index")
    public String index(){
        return "subTemplate/login";
    }

    @PostMapping("/login")
    public String login(String name, String password, Model model){
        log.info("name={},password={}", name, password);
        TestTable testTable = service.getObjByNameAndPSW(name,password);
        if (Objects.nonNull(testTable)){
            model.addAttribute("testTable",testTable);
            return "success";
        } else {
            model.addAttribute("msg", "用户名或密码错误");
            return "err";
        }
    }
}

